<template>
	<view class="content">
		<view class="info">
			<view class="info1">
				<text>姓名</text>
				<input type="text" v-model="nm" value="" placeholder="请输入姓名" placeholder-class="inputStyle" />
			</view>
			<view class="info1">
				<text>手机号</text>
				<input type="text" v-model="phnNum" value="" placeholder="请输入手机号" placeholder-class="inputStyle" @ />
			</view>
			<view class="info1">
				<text>身份证号</text>
				<input type="text" v-model="idNum" value="" placeholder="请输入身份证号" placeholder-class="inputStyle" />
			</view>
		</view>
		<view class="idCrd">
			<text style="margin-bottom: 20rpx;">身份证正反面</text>
			<view class="ddd">
				<view v-for="(item, index) in tempFilePaths" :key="index" v-if="tempFilePaths">
					<view class="image" @click="changeImg(index)"><image :src="item" mode="aspectFill"></image></view>
				</view>
				<view class="image" @click="shanchuan" v-if="tempFilePaths.length < 2"><u-icon name="plus" color="#ccc" size="50"></u-icon></view>
			</view>
		</view>

		<view class="confirmUpload" @click="confirmUp" v-if="!tempFilePaths">确认上传</view>
		<view class="confirmUpload" @click="confirmUp" v-else>确认修改</view>
	</view>
</template>

<script>
import uploadImage from '../../../common/ossutil/uploadFile.js';
export default {
	data() {
		return {
			tempFilePaths: [],
			nm: '',
			phnNum: '',
			idNum: '',
			idLst: [],
			//action: 'https://cp.qianjitianxia.com/api/upload/wx_upload',
			data: {}
		};
	},
	onLoad() {
		this.getCertified();
	},
	methods: {
		shanchuan() {
			var  _this = this
			uni.chooseImage({
				count: 1,
				sourceType: ['album'],
				success: res => {
					uni.showLoading({
						mask: true
					});
					uploadImage(res.tempFilePaths[0], 'car/', result => {
						
						//console.log('result :>> ', result);
						
						this.tempFilePaths = [result,this.tempFilePaths[0], ];
						
						//_this.tempFilePaths.push(result) 
						
						console.log('_this.tempFilePaths :>> ', _this.tempFilePaths);
						uni.hideLoading();
					});
				}
			});
		},

		changeImg(i) {
			uni.chooseImage({
				count: 1,
				sourceType: ['album'],
				success: res => {
					uni.showLoading({
						mask: true
					});

					uploadImage(res.tempFilePaths[0], 'car/', result => {
						this.tempFilePaths[i] = result;
						let tempFilePaths = this.tempFilePaths;
						this.tempFilePaths = [];
						this.tempFilePaths = tempFilePaths;
						console.log('this.tempFilePaths :>> ', this.tempFilePaths);
						uni.hideLoading();
					});
				}
			});
		},

		async confirmUp() {
			if (!this.nm) return uni.$showMsg('请输入姓名');
			let mobileReg = /^(13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\d{8}$/;
			if (!mobileReg.test(this.phnNum)) return uni.$showMsg('请输入正确手机号');
			let idCrdReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
			if (!idCrdReg.test(this.idNum)) return uni.$showMsg('身份证输入不合法');

			const res = await this.$u.post('api/user/user_real_name', {
				uid: getApp().globalData.uid,
				name: this.nm,
				phone: this.phnNum,
				id_number: this.idNum,
				picture: this.tempFilePaths
			});

			uni.switchTab({
				url: '../my'
			});
			uni.$showMsg(res.msg);
		},
		//api/user/get_real_name
		async getCertified() {
			const { data, code, msg } = await this.$u.post('api/user/get_real_name', {
				uid: getApp().globalData.uid
			});
			if (!code) return uni.$showMsg();
			this.nm = data.username;
			this.phnNum = data.phone;
			this.idNum = data.id_number;
			this.tempFilePaths = data.picture;
		}
	}
};
</script>

<style lang="scss" scoped>
.content {
	width: 100vw;
	height: 100vh;
	overflow: scroll;
	padding: 30rpx;
	.info {
		width: 690rpx;
		//height: 689rpx;
		background: #2a2929;
		box-shadow: 0rpx 0rpx 18rpx 0rpx rgba(51, 51, 51, 0.1);
		border-radius: 20rpx;
		padding: 25rpx 31rpx 31rpx 31rpx;
		margin: 0 auto;

		.info1 {
			display: flex;
			flex-direction: column;
			justify-content: center;
			height: 131rpx;
			// margin-left: 29rpx;
			border-bottom: 2rpx solid #f1eded;

			text {
				font-size: 36rpx;
				font-family: 'Microsoft YaHei', PingFang SC;
				font-weight: 400;
				color: #ffffff;
			}

			text:before {
				content: '*';
				color: #ff0000;
			}

			.inputStyle {
				font-size: 30rpx;
				font-family: 'Microsoft YaHei', PingFang SC;
				font-weight: 400;
				color: #ffffff;
			}
			input {
				color: #ffffff;
				padding-left: 10rpx;
			}
		}
	}

	.idCrd {
		width: 690rpx;
		//height: 300rpx;
		background: #2a2929;
		border-radius: 20rpx;
		padding: 30rpx;
		margin-top: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.ddd {
			display: flex;
			//justify-content: flex-start;
			flex-wrap: wrap;
			//padding: 0  30rpx;
			image {
				width: 100%;
				height: 100%;
			}
			.image {
				width: 250rpx;
				height: 180rpx;
				border: 1rpx dashed #606266;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-left: 40rpx;
				margin-bottom: 20rpx;
			}
		}
		text {
			height: 34rpx;
			line-height: 34rpx;
			font-size: 36rpx;
			font-family: 'Microsoft YaHei', PingFang SC;
			font-weight: 400;
			color: #ffffff;
		}
		text:before {
			content: '*';
			color: #ff0000;
		}
		/deep/ .u-list-item {
			background: none !important;
			border: 1rpx dashed #606266;
			margin-right: 30rpx !important;
		}
		/deep/ .u-upload {
			// display: flex !important;
			// justify-content: space-between !important;
		}
	}
	.confirmUpload {
		margin: 0 auto;
		margin-top: 99rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690rpx;
		height: 100rpx;
		background: #d60000;
		border-radius: 50rpx;

		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
	}
}
</style>
